<template>
	<view class="container">
		<view class="item-ul mt20">
			<view class="item-li borb flex-align" v-if="isEdit">
				<text class="item-lname">旧密码</text>
				<input class="item-linp flex1" v-model="params.oldpass" :type="oldpassT?'text':'password'" placeholder="请输入密码" maxlength="30">
				<text class="item-licon iconfont" :class="oldpassT?'iconyanjing-xianxing3-0':'iconbiyanjing'" @click="oldPassT()"></text>
			</view>
			<view class="item-li borb flex-align">
				<text class="item-lname">新密码</text>
				<input class="item-linp flex1" v-model="params.newpass" :type="passwordT?'text':'password'" placeholder="请输入新密码" maxlength="30">
				<text class="item-licon iconfont" :class="passwordT?'iconyanjing-xianxing3-0':'iconbiyanjing'" @click="newPass()"></text>
			</view>
			<view class="item-li borb flex-align">
				<text class="item-lname">再次输入</text>
				<input class="item-linp flex1" v-model="params.newpass2" :type="password2T?'text':'password'" placeholder="请再次输入新密码" maxlength="30">
				<text class="item-licon iconfont" :class="password2T?'iconyanjing-xianxing3-0':'iconbiyanjing'" @click="newPass2()"></text>
			</view>
		</view>
		<view class="item-btn flex-center-align" @click="subFun">
			<text>确定</text>
		</view>
	</view>
</template>

<script>
	let that;
	import personalApi from "@/api/personal.js"
	export default {
		data() {
			return {
				isEdit:false,//是否修改密码
				oldpassT:false,//是否显示密码
				passwordT:false,//是否显示密码
				password2T:false,//是否显示密码
				params:{
					oldpass:'',
					newpass:'',
					newpass2:'',
					rLoading:true
				}
			}
		},
		onLoad(e) {
			that = this;
			this.isEdit = e.type==2;
		},
		methods: {
			oldPassT() {
				this.oldpassT=!this.oldpassT
			},
			
			newPass() {
				this.passwordT=!this.passwordT
			},
			newPass2() {
				this.password2T=!this.password2T
			},
			
			//获取数据
			async subFun() {
				let params = this.params;
				if(!this.$common.IsEmpty(params.oldpass) && this.isEdit){return this.$common.msgShow('请输入旧密码')};
				if(!this.$common.IsEmpty(params.newpass)){return this.$common.msgShow('请输入新密码')};
				if(!this.$common.IsEmpty(params.newpass2)){return this.$common.msgShow('请再次输入新密码')};
				if(params.newpass!=params.newpass2){return this.$common.msgShow('两次密码输入不一致')};
				if(!this.isEdit){
					delete params.oldpass
				}
				let res = await personalApi.changepwd(params);
				if (res.code == 1) {
					this.$common.pageBack(res.msg)
				} else {
					this.$common.msgShow(res.msg);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
